package com.study.springboottest.sort;

public class SelectionSortTest {

    public static void main(String[] args) {
        int[] arr = {5, 3, 15, 50, 62, 21, 28, 34, 64, 91, 67};
        int[] ints = selectionSortTest(arr);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(arr[i]);
        }
    }

    //直接排序实现
    public static int[] selectionSortTest(int[] arr) {
        // 获取集合的长度
        int length = arr.length;
        int minIndex;
        int temp;
        for (int i = 0; i < length - 1; i++) {
            minIndex = i;
            for (int j = i + 1; j < length; j++) {
                if (arr[j] < arr[minIndex]) {
                    minIndex = j;
                }
            }
            temp = arr[minIndex];
            arr[minIndex] = arr[i];
            arr[i] = temp;
        }
        return arr;
    }
}
